package com.github.phoenics.bazooka.dao;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.phoenics.bazooka.domain.po.Room;
import com.github.phoenics.bazooka.domain.po.Student;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author Phoenics Chow
 * on 2019年01月27日
 */
@Mapper
public interface RoomDao extends BaseMapper<Room> {
    @Select("SELECT\n" +
            "student.id,\n" +
            "student.s_name,\n" +
            "student.s_reademe,\n" +
            "student.room_id\n" +
            "FROM\n" +
            "student\n" +
            "INNER JOIN room ON room.id = student.room_id " +
            "${ew.customSqlSegment}")
    List<Student> findStudents(@Param(Constants.WRAPPER) Wrapper wrapper);
    IPage<Student> findStudents(Page page,@Param(Constants.WRAPPER) Wrapper wrapper);
    default  List<Student> findStudentsById(Long id){
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("room.id",id);
        return this.findStudents(wrapper);
    }
    default IPage<Student> findStudentsById(Page<Student> page,Long id){
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("room.id",id);
        return this.findStudents(page,wrapper);
    }

}
